package edu.gmu.atelier;

import java.util.ArrayList;
import java.util.List;

/**
 * Vector defined within some vector space.
 * @author James H. Pope
 */
public class StandardVector implements Vector
{
    private int position = 0;
    private int n = 0;
    
    public StandardVector(int pos, int n)
    {
        this.position = pos;
        this.n = n;
    }
    
    //------------------------------------------------------------------------//
    // Interface methods
    //------------------------------------------------------------------------//
    public Element norm2()
    {
        return new RealElement(1);
    }
    
    public Vector normalize()
    {
        // ???
        return this;
    }
    
    public Vector add(Vector v)
    {
        throw new UnsupportedOperationException("Not supported yet.");
    }
    
    public Vector sub(Vector v)
    {
        throw new UnsupportedOperationException("Not supported yet.");
    }
    
    public Vector mult(Element e)
    {
        throw new UnsupportedOperationException("Not supported yet.");
    }
    
    public Element dot(Vector v )
    {
        throw new UnsupportedOperationException("Not supported yet.");
    }
    
    public Element getElement(int i)
    {
        if(i == position)
        {
            return new RealElement(1.0);
        }
        return new RealElement(0.0);
    }
    
    public void setElement(int i, Element e)
    {
        throw new UnsupportedOperationException("Not supported yet.");
    }
    
    
    public int getLength()
    {
        return this.n;
    }
    
    
    public Vector mult( IMatrix a )
    {
        //java.util.List<Vector> vectors = a.getVectors();
        // Easy, copy vector to return at position
        return a.getVector( this.position ).copy();
    }
    
    /**
     * Returns true is all the elements are the zero element.
     * @param
     */
    public boolean isZero()
    {
        throw new UnsupportedOperationException("Not supported.");
    }
    
    public StandardVector copy()
    {
        return new StandardVector(this.position, this.n);
    }
    
    public ComplexVector copy(int start, int length)
    {
        throw new UnsupportedOperationException("Not supported.");
    }
    
    public void copyElements(int start, Vector v)
    {
        throw new UnsupportedOperationException("Not supported.");
    }
    
    public Matrix transpose( Matrix a )
    {
        List<Vector> vectors = a.getVectors();
        List t = new ArrayList<Vector>();
//        int n = vectors.size();
//        int m = vectors.get(0).getLength();
//        
//        for (int i = 0; i < m; i++)
//        {
//            double[] c = new double[n];
//            for (int j = 0; j < n; j++)
//            {
//                c[j] = ((StandardVector)vectors.get(j)).elements[i];
//            }
//            t.add( new StandardVector(c) );
//        }
        return new Matrix(t, a.getFactory());
    }
    
    public Vector extract( int[] B )
    {
        throw new UnsupportedOperationException("Not supported.");
    }
    
    public void extractTo( int[] B, Vector b )
    {
        throw new UnsupportedOperationException("Not supported.");
    }
    
    //------------------------------------------------------------------------//
    // "Row" mutator operations
    //------------------------------------------------------------------------//
    public void swap( int fromRow, int toRow )
    {
        throw new UnsupportedOperationException("Not supported.");
    }
    
    public void mulAddTo( int fromRow, Element mult, int toRow )
    {
        throw new UnsupportedOperationException("Not supported.");
    }
    
    public void mulTo( int row, Element mult )
    {
        throw new UnsupportedOperationException("Not supported.");
    }
    
    //------------------------------------------------------------------------//
    // Class instance methods
    //------------------------------------------------------------------------//
    public boolean similar( Object obj, Epsilon e )
    {
        if(obj == this)
        {
            return true;
        }
        
        if( (obj instanceof StandardVector) == false )
        {
            return false;
        }
        
        StandardVector o = (StandardVector)obj;
        
        if( o.position != this.position ||
                o.n != this.n)
        {
            return false;
        }
        return true;
    }
    
    public boolean equals( Object obj )
    {
        return this.similar(obj, null);
    }
    
    public String toString()
    {
        StringBuilder buf = new StringBuilder("[");
        for (int i = 0; i < n; i++)
        {
            if( i == this.position ) 
            {
                buf.append( 1.0 );
            }
            else
            {
                buf.append( 0.0 );
            }
            buf.append( "," );
        }
        buf.append("]");
        return buf.toString();
    }
}
